Skip to content

feat: auto-discover target-keyed agent-context sidecars - #540

Open
alleneubank wants to merge 1 commit into
modem-dev:mainfrom
alleneubank:feat/agent-context-auto-discovery
Open

feat: auto-discover target-keyed agent-context sidecars#540
alleneubank wants to merge 1 commit into
modem-dev:mainfrom
alleneubank:feat/agent-context-auto-discovery

Conversation

@alleneubank

@alleneubank alleneubank commented Jul 14, 2026

Copy link
Copy Markdown

Summary

  • Auto-discover target-keyed agent-context sidecars: .hunk/agent-context.<targetId>.json for the current review target (working tree, staged, range, show, stash-show + sorted pathspecs)
  • Never auto-load bare .hunk/agent-context.json (that was the confusing partial-attach case). Explicit --agent-context / config agent_context still load any path, including a legacy bare name
  • Keep explicit/configured paths strict; conventional keyed path is best-effort (missing/malformed → no notes, review continues)
  • Show agent notes when a sidecar actually loads; --no-agent-context opt-out; exclude .hunk/ metadata from untracked review noise
  • Document the convention (README, agent-workflows, hunk-review skill) + minor Changeset

Why (response to review)

@benvinegar called out that unscoped auto-discovery of a fixed bare sidecar can load notes against a different review and partially apply them. This revision keys discovery on review target identity in the filename (not patch content hash, which would thrash on every working-tree edit). Same pure function for discovery, watch, and agent skill guidance.

targetId = first 12 hex of SHA-256 over a canonical target string. Users never type it; agents write the conventional path for the same CLI args they open the review with.

User impact

Before After
Bare .hunk/agent-context.json auto-loaded on every hunk diff / show / range Only .hunk/agent-context.<id>.json for this target auto-loads
One shared file for all reviews Multiple sidecars can coexist per range/show/WT
Partial attach across mismatched targets Wrong-id file ignored; no dual bare+keyed auto-read

Verification

  • bun run typecheck
  • focused: bun test src/core/agentContextPath.test.ts src/core/config.test.ts src/core/agent.test.ts (78 pass)
  • bun run typecheck on this branch tip

Notes for cherry-pick

Single feat commit on current main. No SPEC/BRIEF/LOOP campaign docs on this PR.

@alleneubank
alleneubank marked this pull request as ready for review July 14, 2026 16:41
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@benvinegar

Copy link
Copy Markdown
Member

I think this is a good idea, but I'd want it to somehow match the changeset/rev range somehow. e.g. the next time you run hunk diff, it could be a different diff, and the comments would be stale / not apply / could partially apply (confusing).

So I think we'd want some kind of id in the sidecar json filename.

Auto-load `.hunk/agent-context.<targetId>.json` for the current review target so
notes for one range or show do not attach on another. Bare `agent-context.json`
is never auto-discovered; explicit and config paths stay strict.

Implements maintainer feedback on modem-dev#540: discovery is scoped by
review-target identity in the filename, not a single repo-wide bare path.
@alleneubank
alleneubank force-pushed the feat/agent-context-auto-discovery branch from 3d4413d to fbee662 Compare August 11, 2026 21:12
@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@alleneubank is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

@alleneubank alleneubank changed the title feat: auto-discover agent context sidecars feat: auto-discover target-keyed agent-context sidecars Aug 11, 2026
@alleneubank

Copy link
Copy Markdown
Author

@benvinegar — thank you for the review on the earlier auto-discovery shape.

We took your suggestion: discovery is now target-scoped via the filename, not a single bare .hunk/agent-context.json.

Convention: .hunk/agent-context.<targetId>.json
where targetId is the first 12 hex chars of SHA-256 over a canonical review-target string (working-tree / staged / range+expression / show+ref / stash-show+ref + sorted pathspecs). Same pure function for load, watch, and agent guidance.

Guarantees:

  • A sidecar written for hunk diff main...HEAD does not auto-load on bare hunk diff
  • Two ranges in one repo can each keep a sidecar without clobbering
  • Explicit --agent-context / config still load any path (including a legacy bare name if someone wants that)
  • Missing keyed file → review works, no notes (best-effort)

We deliberately did not put a full patch content hash in the filename (working-tree thrash / agents rewriting the name every edit). Content drift still soft-fails via existing range matching.

Happy to adjust further if you want a different canonical payload or id length.

alleneubank added a commit to alleneubank/hunk that referenced this pull request Aug 11, 2026
Auto-load `.hunk/agent-context.<targetId>.json` for the current review target so notes for one range or show do not attach on another. Bare `agent-context.json` is never auto-discovered; explicit and config paths stay strict. Export reports `agentContextPath` for agents (modem-dev#540).
alleneubank added a commit to alleneubank/hunk that referenced this pull request Aug 11, 2026
Pure viewport-scroll interaction fixtures set initialCursorLine off so arrows
call scrollDiff instead of moveLineCursor. Align bootstrap-prefs note order
with note-after-annotated-line layout. LOOP.md marks campaign interior-green
with floor citations and human handoff for modem-dev#540.
alleneubank added a commit to alleneubank/hunk that referenced this pull request Aug 12, 2026
Integrate the VS Code extension, headless review, viewed state, and standing
SPEC/BRIEF with the clean modem-dev#540 agent-context commit on current upstream/main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants